#ifndef VIDEOCARD_H_
#define VIDEOCARD_H_

#include "../../sim.h"

// pixel format
#define VIDEO_PIXELFORMAT 16
//#if SDL_BYTEORDER == SDL_BIG_ENDIAN
//#else
//#define VIDEO_rmask 0x0000001f
//#define VIDEO_gmask 0x000007e0
//#define VIDEO_bmask 0x0000f800
//#define VIDEO_amask 0x00000000
//#endif
#define VIDEO_PIXELSIZE (VIDEO_PIXELFORMAT/8)

// screen/playfield geometry
#define VIDEO_WIDTH 480 // physical width
#define VIDEO_HEIGHT 272 // physical height
#define VIDEO_PLAYFIELDWIDTH 512
#define VIDEO_PLAYFIELDHEIGHT 512
#define VIDEO_HBLANKPERIOD 40 //FIXME
#define VIDEO_VBLANKPERIOD 80 //FIXME
#define VIDEO_ACTIVEPIXELS (VIDEO_WIDTH * VIDEO_HEIGHT)
#define VIDEO_TOTALPIXELS ((VIDEO_WIDTH + VIDEO_HBLANKPERIOD) * (VIDEO_HEIGHT + VIDEO_VBLANKPERIOD))
//

// timing
#define VIDEO_REFRESHRATE 50
#define VIDEO_PIXELCLOCK (VIDEO_TOTALPIXELS * VIDEO_REFRESHRATE)
#define VIDEO_MACHINECLOCKSPERPIXELCLOCK (SIM_MAINCLOCK/VIDEO_PIXELCLOCK)
//

#define VIDEO_REG_FLAGS 0
#define VIDEO_REG_CONFIG 2
#define VIDEO_REG_PIXEL 4
#define VIDEO_REG_LINE 6
#define VIDEO_REG_FRAME 8
#define VIDEO_REG_POSX 10
#define VIDEO_REG_POSY 12
#define VIDEO_REG_WINX 14
#define VIDEO_REG_WINY 16
#define VIDEO_REG_WINWIDTH 18
#define VIDEO_REG_WINHEIGHT 20

// memory size/offsets
#define VIDEO_FRAMEBUFFER_SIZE ((VIDEO_PLAYFIELDWIDTH * VIDEO_PLAYFIELDHEIGHT) * VIDEO_PIXELSIZE)
#define VIDEO_FRAMEBUFFER_START 0x80000
#define VIDEO_COMPOSITINGBUFFER_SIZE 1024
#define VIDEO_COMPOSITINGBUFFER_START (VIDEO_FRAMEBUFFER_START + VIDEO_FRAMEBUFFER_SIZE)
//

#include "card.h"

const card videocard;

#include <SDL/SDL.h>
void videocard_render(SDL_Surface* screen);

#endif
